<template>
    <h2>房号添加页面</h2>
    <table border="1">
        <tr>
            <td>房号名称</td>
            <input type="text" v-model="info.trN_Name"/>
        </tr>
        <tr>
            <td>状态</td>
            <td>
                <input type="radio" v-model="info.trN_State" :value="true"/>上架
                <input type="radio" v-model="info.trN_State" :value="false"/>下架
            </td>
        </tr>
        <tr>
            <td>备注</td>
            <td>
                <textarea v-model="info.trN_Info">

                </textarea>
            </td>
        </tr>
        <tr>
            <input type="button" value="添加" @click="Add"/>
        </tr>
    </table>
</template>
<script setup lang="ts">
    import {ref,onMounted} from 'vue';
    import axios from 'axios';

    const info=ref({
        trN_Name: "",
        trN_State: true,
        trN_Info: ""
    })

    //添加
    const Add=()=>{
        axios.post("https://localhost:7038/api/RoomNumber/AddRoomNumber",info.value)
        .then(res=>{
            if(res.data>0){
                alert('添加成功');
                router.push({
                    name:"ShowRoomNumber"
                })
            }
            else if(res.data==-1){
                alert('相同的房号的不能录入多次');
            }
            else{
                alert('添加失败');
            }
        })
        .catch(err=>{
            console.log(err);
        })
    }
</script>
